Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hmr): Use resolveTemplateUsageCheckString in vite/plugin-vue. #4908

Merged
merged 2 commits into from
Nov 26, 2021

Conversation

ygj6
Copy link
Member

@ygj6 ygj6 commented Nov 6, 2021

@ygj6 ygj6 requested review from edison1105 and yyx990803 and removed request for edison1105 November 6, 2021 09:17
@ygj6
Copy link
Member Author

ygj6 commented Nov 6, 2021

vitejs/vite#5561 use resolveTemplateUsageCheckString to determine whether the reference variable in the template has been changed.

function needGlobHMR(
  prev: SFCDescriptor | null,
  next: SFCDescriptor | null
): boolean {
  const isDynamicUpdate = resolveTemplateUsageCheckString(prev!) !== resolveTemplateUsageCheckString(next!)
  const prevSetup = prev!.scriptSetup
  const nextSetup = next!.scriptSetup
  const isSetupWithTS = !!(
    prevSetup?.setup &&
    nextSetup?.setup &&
    (prevSetup.lang === 'ts' || prevSetup.lang === 'tsx')
    && (nextSetup.lang === 'ts' || nextSetup.lang === 'tsx')
  )
  return isDynamicUpdate && isSetupWithTS
}

@yyx990803 yyx990803 merged commit c61baac into vuejs:master Nov 26, 2021
yyx990803 added a commit that referenced this pull request Nov 26, 2021
@yyx990803
Copy link
Member

FYI I tested this further with local plugin-vue changes and determined this is sub-optimal - this would cause the component to reload instead of re-render in more cases than necessary (for example any template expression change would cause a reload with the proposed changes in vitejs/vite#5561)

The more accurate approach is to get a hold of the imports data from the previous compileScript call, and then check whether it changed from "unused" to "used" status in the new descriptor. See 68c45e7 (vite plugin-vue patch coming soon)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid vnode type when creating vnode: undefined.
2 participants